package vip.bblog.cunadmin.modules.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.bblog.cunadmin.common.entity.PageResult;
import vip.bblog.cunadmin.modules.system.dto.ProjectParams;
import vip.bblog.cunadmin.modules.system.entity.Publisher;
import vip.bblog.cunadmin.modules.system.entity.Customer;
import vip.bblog.cunadmin.modules.system.mapper.PublisherMapper;
import vip.bblog.cunadmin.modules.system.mapper.CustomerMapper;
import vip.bblog.cunadmin.modules.system.service.PublisherService;

import java.util.List;

/**
 * <p>
 * 包厢
 * </p>
 * @author yy
 * @since
 */
@Service
public class PublisherServiceImpl extends ServiceImpl<PublisherMapper, Publisher> implements PublisherService {

    @Autowired
    private PublisherMapper roomMapper;
    @Autowired
    private CustomerMapper shopMapper;

    @Override
    public PageResult<List<Publisher>> listPage(ProjectParams params) {
        Page<Publisher> page = params.getIPage();
        QueryWrapper<Publisher> queryWrapper = new QueryWrapper();
        //根据发行商查询
        if (StringUtils.isNotBlank(params.getName())){
            queryWrapper.eq("name", params.getName());
        }
        if(StringUtils.isNotBlank(params.getInPulisherId())){
            String[] ids = params.getInPulisherId().split(",");
            queryWrapper.in("id", ids);
        }
        queryWrapper.orderByDesc("create_time");
        Page<Publisher> pageResult = this.page(page, queryWrapper);
        List<Publisher> list = pageResult.getRecords();

        return PageResult.success(list, pageResult.getTotal());
    }

    @Override
    public IPage<Publisher> getByPage(ProjectParams entity){
        Page<Publisher> page = new Page<>(entity.getPage(), entity.getPageSize());
        IPage<Publisher> pagelist = roomMapper.getByPage(page, entity);
        return pagelist;
    }

}
